package com.example.lots_of_demo.utils;

import com.example.lots_of_demo.model.REnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author : LZJ
 * @description : code for LZJ
 * @date : 2021/2/11
 */
@Data
@AllArgsConstructor
@Accessors
public class R {

    /**
     * 响应码
     */
    private String code;
    /**
     * 响应信息
     */
    private String msg;
    /**
     * 响应消息体
     */
    private Object data;

    public R(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static R createSuccess(REnum.RSuccessResponse response){
        return new R(response.getCode(), response.getDesc());
    }

    public static R createSuccess(REnum.RSuccessResponse response,Object data){
        return new R(response.getCode(), response.getDesc(), data);
    }

    public static R createFail(REnum.RFailResponse response){
        return new R(response.getCode(), response.getDesc());
    }

}
